<template>
    <div>
        <el-card class="box-card">
            <!-- 卡片，顶部添加按钮 -->
            <el-button type="primary" size="default" icon="plus" @click="addTrademark">添加品牌</el-button>

            <!-- 表格组件 -->
            <!-- 
          table 表格
            ---border: 是否有边框
          table-column
            ---label 设置表头名称
            ---width 设置列宽
            ---align 设置对齐方式

         -->
            <el-table style="margin: 10px 0px;" border :data="trademarkArr">
                <el-table-column label="序号" width="80px" align="center" type="index"> </el-table-column>
                <!-- 默认展示数据使用Div -->
                <el-table-column label="品牌名称">
                    <template #="{ row }">
                        <pre>{{ row.tmName }}</pre>
                    </template>
                </el-table-column>
                <el-table-column label="品牌LOGO">
                    <template #="{ row }">
                        <img :src="row.logurl" alt="" style="width: 50px; height: 50px;" />
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template #="{ row }">
                        <el-button size="small" type="primary" icon="Edit" @click="updateTrademark(row)"></el-button>
                        <el-popconfirm width="400" confirm-button-text="确认" cancel-button-text="取消" icon="InfoFilled"
                            icon-color="#626AEF" title="您确定要删除此条数据吗?">
                            <template #reference>
                                <el-button size="small" type="primary" icon="Delete"
                                    @click="deleteTrademark"></el-button>
                            </template>
                        </el-popconfirm>

                    </template>
                </el-table-column>
            </el-table>

            <!-- 分页组件 -->
            <!-- 
        el-pagination
            ---v-model:current-page 设置当前页码
            ---v-model:page-size 设置每页显示条数
            ---page-sizes 设置每页条数选择器的选项
            ---small 是否使用小型分页
            ---disabled 是否禁用分页
            ---background 设置分页器背景颜色
            ---layout 设置分页布器6个子组件布局
                ---total 显示总条数
                ---sizes 每页条数选择器
                ---prev 上一页
                ---pager 页码
                ---next 下一页
                ---jumper 跳转页码
            ---total 总条数
            ---@size-change 每页条数改变时触发的事件
            ---@current-change 当前页码改变时触发的事件
         -->
            <el-pagination @size-change="sizeChange" @current-change="getHasTrademark" :pager-count="9"
                v-model:current-page="currentPage4" v-model:page-size="pageSize4" :page-sizes="[3, 5, 7, 9]"
                :background="true" layout="prev, pager, next, jumper,->,sizes,total" :total="total" />

        </el-card>

        <!-- 对话框组件 -->
        <el-dialog v-model="dialogFormVisible" title="添加品牌">
            <el-form ref="formRef" style="width: 80%;">
                <el-form-item label="品牌名称" prop="name" label-width="100px">
                    <el-input placeholder="请输入品牌名称" v-model="trademarkName" />
                </el-form-item>
                <el-form-item label="品牌LOGO" prop="name" label-width="100px">


                    <el-upload class="avatar-uploader">
                        <!-- <img v-if="imageUrl" :src="imageUrl" class="avatar" /> -->
                        <el-icon class="avatar-uploader-icon">
                            <Plus />
                        </el-icon>
                    </el-upload>
                </el-form-item>
            </el-form>

            <template #footer>
                <el-button type="primary" size="default" @click="cancel">取消</el-button>
                <el-button type="primary" size="default" @click="confirm">确定</el-button>
            </template>

        </el-dialog>
    </div>
</template>

<script setup lang='ts' name='Trademark'>
import { onMounted, ref } from 'vue';
import { reqTradeMarkList } from '@/api/product/trademark';
import type { TradeMark, TradeMarkDetail } from '@/api/product/trademark/type';

/// 绑定当前页码
let currentPage4 = ref<number>(1)
/// 每页条数
let pageSize4 = ref<number>(3)
/// 总数
let total = ref<number>(0)
/// 数据
let trademarkArr = ref<TradeMarkDetail[]>([])
/// 控制对话框显示隐藏
let dialogFormVisible = ref<boolean>(false)
/// 品牌名称
let trademarkName = ref<string>('')

const getHasTrademark = async () => {
    // 获取品牌列表
    let result: TradeMark = await reqTradeMarkList(currentPage4.value, pageSize4.value)
    if (result.code === 200) {
        // 获取数据成功
        total.value = result.data.total;
        trademarkArr.value = result.data.data;
    }
}

onMounted(() => {
    // 获取品牌列表
    getHasTrademark()
});

// 分页器页面发生变化触发
const sizeChange = () => {
    currentPage4.value = 1
    getHasTrademark()
}

// 添加品牌
const addTrademark = () => {
    // 显示对话框
    dialogFormVisible.value = true
}

// 修改品牌
const updateTrademark = (value: any) => {
    console.log(value)
    // 显示对话框
    dialogFormVisible.value = true
}

// 删除品牌
const deleteTrademark = () => {

}

// 取消
const cancel = () => {
    // 关闭对话框
    dialogFormVisible.value = false
}

// 确定添加品牌
const confirm = () => {
    // 关闭对话框
    dialogFormVisible.value = false
}

</script>


<style scoped>
.avatar-uploader .avatar {
    width: 178px;
    height: 178px;
    display: block;
}
</style>

<style>
.avatar-uploader .el-upload {
    border: 1px dashed var(--el-border-color);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
    border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    text-align: center;
}
</style>